function get(key) {
	if (!key || !_has(key)) {
		return '';
	}
	return uni.getStorageSync(key)
}

function all() {
	return uni.getStorageInfoSync()
}

function set(key, data) {
	if (!key) {
		return;
	}
	uni.setStorageSync(key, data)
}

function remove(key) {
	if (!key || !_has(key)) {
		return;
	}
	uni.removeStorageSync(key)
}

function clearAll() {
	const res = uni.getStorageInfoSync();
	res.keys.map((item) => {
		if (item == 'tsapp_token' || item == 'spread') {
			return
		}
		remove(item)
	})
}

function _has(key) {
	if (!key) {
		return
	}
	let value = uni.getStorageSync(key)
	if (value) {
		return true
	}
	return false
}



function setToken(value) {
	set('tsapp_token', value)
}

function getToken() {
	return get('tsapp_token')
	// return 'rabbit_2023_token_f599ab8d5e33468f971b2df57c0be300'
}
function setArea(value) {
	set('tsapp_area', value)
}
function getArea() {
	return get('tsapp_area')
}

function removeArea() {
	remove('tsapp_area')
}

function setLanguage(value) {
	set('tsapp_language', value)
}

function getLanguage() {
	return get('tsapp_language')
}
function setCounty(value) {
	set('tsapp_county', value)
}

function getCounty_() {
	return get('tsapp_county')
}

function setLan(value) {
	set('tsapp_lan', value)
}

function getLan() {
	return get('tsapp_lan')
}

function setAddress(value) {
	set('tsapp_address', value)
	setShortAddress(value)
}

function getAddress() {
	return get('tsapp_address')
}

function setShortAddress(value) {
	var addr = value.toString();
	var start = addr.substring(0,6);
	var end = addr.substring(addr.length - 6, addr.length);
	addr = start + "..." + end
	set('tsapp_shortAddress', addr)
}

function getShortAddress() {
	return get('tsapp_shortAddress')
}

function setChain(value) {
	set('tsapp_chain', value)
}

function getChain() {
	return get('tsapp_chain')
}

function removeAddressToken() {
	remove('tsapp_token')
	remove('tsapp_address')
	remove('tsapp_shortAddress')
}

function isConnected() {
	if (getAddress() && getToken()) {
		return true
	} else {
		removeAddressToken()
		return false
	}
}


export default {
	get,
	all,
	set,
	remove,
	clearAll,
	has: _has,
	isConnected,
	removeAddressToken,
	getChain,
	getShortAddress,
	getAddress,
	setAddress,
	getToken,
	setToken,
	setCounty,
	getCounty_,
	setLanguage,
	getLanguage,
	setLan,
	getLan,
	setArea,
	getArea,
	removeArea
}